﻿using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace PrismStudy.ViewModels
{
    class ViewAViewModel : BindableBase, IConfirmNavigationRequest
    {
        private string title;
        public string Title { 
            get { return title; }
            set { title = value;RaisePropertyChanged(); }
        }

        //导航前触发，可以进行询问
        public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
        {
            bool result = true;
            /*if (MessageBox.Show("确认导航？","提示",MessageBoxButton.YesNo)==MessageBoxResult.No)
            {
                result = false;
            }*/
            continuationCallback(result);
        }

        /// <summary>
        /// 判断View是否创建过
        /// </summary>
        /// <param name="navigationContext"></param>
        /// <returns></returns>
        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;//重新创建
        }

        /// <summary>
        /// 导航离开当夜时触发
        /// </summary>
        /// <param name="navigationContext"></param>
        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
            
        }

        /// <summary>
        /// 导航完成前，接受用户传递的参数，以及是否允许导航控制
        /// </summary>
        /// <param name="navigationContext"></param>
        public void OnNavigatedTo(NavigationContext navigationContext)
        {
           Title = navigationContext.Parameters.GetValue<string>("param");
        }
    }
}
